﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DiBang.Common;
using DiBang.Sql;

namespace ChangWuDiBang
{
    public partial class FrmPwdChange : Office2007Form
    {
        public UserInfo _UserInfo
        {
            get;
            set;
        }

        SqlExtend sqlextend = new SqlExtend();
        SqlLib sqllib = new SqlLib();

        public FrmPwdChange()
        {
            this.EnableGlass = false;
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (!txtSecPwd.Text.Equals(txtFirstPwd.Text))
            {
                MessageBoxEx.Show("新密码两次不相同!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtSecPwd.Clear();
                txtFirstPwd.Clear();
                txtFirstPwd.Focus();
                return;
            }

            if (!sqlextend.UserPwdCheck(_UserInfo.UserID, txtOldPwd.Text))
            {
                MessageBoxEx.Show("密码不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Dictionary<string, object> setMap = new Dictionary<string, object>();
            setMap.Clear();
            setMap.Add("USER_PWD", Base64Encoding.BaseEncoding(txtFirstPwd.Text.Trim()));
            Dictionary<string,object> whereMap=new Dictionary<string,object>();
            whereMap.Clear();
            whereMap.Add("USER_ID",_UserInfo.UserID);

            if(sqllib.UpdateTable("DB_USER",setMap,whereMap)>-1)
            {
                MessageBoxEx.Show("密码修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
